package com.huluobo.a2206koltindouyin.adapter

import android.animation.ObjectAnimator
import android.media.Image
import android.view.View
import android.view.animation.LinearInterpolator
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.huluobo.a2206koltindouyin.R
import com.huluobo.a2206koltindouyin.utils.ImageUtils
import com.huluobo.base.bean.VideoBean
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer

/**
 *  Created by LC on 2024/10/30.
 */
class VideosAdapter : BaseQuickAdapter<VideoBean, BaseViewHolder>(R.layout.item_videos) {
    override fun convert(holder: BaseViewHolder, item: VideoBean) {
        val player = holder.getView<StandardGSYVideoPlayer>(R.id.item_videos_player)
        player.backButton.visibility = View.GONE
        player.setUp(item.videopath, true, "")

        holder.setText(R.id.item_videos_address_tv, item.address)
        holder.setText(R.id.item_videos_authname_tv, item.authname)
        holder.setText(R.id.item_videos_caption_tv, item.caption)
        holder.setText(R.id.item_videos_pao_tv, "${item.authname}的原创作品")

        ImageUtils.loadCircleImage(context, item.headpath, holder.getView(R.id.item_videos_header_iv))
        if (item.guanzhu == 0) {
            holder.getView<ImageView>(R.id.item_videos_add_iv).visibility = View.VISIBLE
        } else {
            holder.getView<ImageView>(R.id.item_videos_add_iv).visibility = View.GONE
        }
        if (item.dianzan == 0) {
            holder.setImageResource(R.id.item_videos_like_iv, R.drawable.ic_xihuan)
        } else {
            holder.setImageResource(R.id.item_videos_like_iv, R.drawable.ic_xihuanred)
        }
        holder.setText(
            R.id.item_videos_like_count_tv,
            if (item.like_count < 10000) item.like_count.toString() else "${item.like_count / 10000}W"
        )
        holder.setText(R.id.item_videos_comment_count_tv, "3.5W")
        holder.setText(R.id.item_videos_collect_count_tv, "2.5W")
        holder.setText(R.id.item_videos_share_count_tv, "1.5W")
        val musicPlayer = holder.getView<ImageView>(R.id.item_videos_music_player_iv)
        ImageUtils.loadCircleImage(context, item.headpath, musicPlayer)

        val animator: ObjectAnimator = ObjectAnimator.ofFloat(musicPlayer, "Rotation", 0f, 360f)
        animator.duration = 3000;
        animator.repeatCount = -1
        animator.interpolator = LinearInterpolator()
        animator.start()
    }
}